package com.littleHan.brushQuestions.web.start.controller;

import com.alibaba.fastjson.JSON;
import com.littleHan.brushQuestions.common.Result;
import com.littleHan.brushQuestions.utils.GetTokenInfoUtil;
import com.littleHan.brushQuestions.web.start.pojo.GeneralUser;
import com.littleHan.brushQuestions.web.start.pojo.Permission;
import com.littleHan.brushQuestions.web.start.pojo.Role;
import com.littleHan.brushQuestions.web.start.service.LoginService;
import com.littleHan.brushQuestions.web.start.service.PermissionService;
import com.littleHan.brushQuestions.web.start.service.RoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;

    /**
     * 未登录(非法请求)情况给前端打回401状态码
     * @return
     */
    @RequestMapping(value="/toLastIndex",method = RequestMethod.GET)
    public String noneRegister(){
        return JSON.toJSONString(new Result().setCode(402).setMessage("请先登录!"));
    }

    /**
     * 登录方法
     * @param generalUser
     * @return
     */
    @RequestMapping(value = "/go",method = RequestMethod.POST)
    public String test(@RequestBody GeneralUser generalUser){
        String info=loginService.loginDealWith(generalUser);
        return info;
    }

    /**
     * 检查用户是否登录
     */
    @GetMapping(value = "/checkLogin")
    public String checkLogin(HttpServletRequest request) {
        //String userId= GetTokenInfoUtil.getUserId(request);
        return JSON.toJSONString(new Result().setCode(200).setMessage("登录状态").setData(loginService.checkLogin(request)));
    }



}
